package com.sky.controller.user;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

/**
 * 店铺控制器
 */
@RestController("userShopController")
@Slf4j
@RequestMapping("/user/shop")
@Api(tags = "店铺控制器")
public class ShopController {

    private static final String SHOP_STATUS = "SHOP_STATUS";

    @Autowired
    private RedisTemplate redisTemplate;




    @GetMapping("/status")
    public Result<Integer> getStatus(){
        log.info("[获取营业状态]");
        Integer status = (Integer)redisTemplate.opsForValue().get(SHOP_STATUS);
        // 如果返回是null,我们做默认处理，最终解释权问产品
        if (status == null){
            redisTemplate.opsForValue().set(SHOP_STATUS,1);
            status = 1;
        }
        return Result.success(status);
    }
}
